package test.student;

import java.util.Arrays;

public class Student  implements Comparable {
    private String name;
//    private String gender;
//    private short age;
    private double score;

    public Student(String name,double score){
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "[" + this.name + ":" + this.score + "]";
    }

    @Override
    public int compareTo(Object o) {
        Student a = (Student) o;
        if (this.score > a.score) {
            return -1;
        } else if (this.score < a.score) {
            return 1;
        } else {
            return 0;
        }
    }


    public static void sort(Comparable[] array) {
        for (int bound = 0; bound < array.length; bound++) {
            for (int cur = array.length - 1; cur > bound; cur--) {
                if (array[cur - 1].compareTo(array[cur]) > 0) {
                    // 说明顺序不符合要求, 交换两个变量的位置
                    Comparable tmp = array[cur - 1];
                    array[cur - 1] = array[cur];
                    array[cur] = tmp;
                }
            }
        }
    }


    //    static {
//        name = "张三";
//    }

//    public static String getStudent(){
//        return name;
//    }
//    public static void show(){
//        System.out.println(name);
//    }

    public static void main(String[] args) {
        Student[] students = new Student[] {
            new Student("张三", 95),
            new Student("李四", 96),
            new Student("王五", 97),
            new Student("赵六", 92),
        };
        sort(students);
        System.out.println(Arrays.toString(students));




//        System.out.println(Student.name); //通过类名直接访问静态成员变量
//
//        System.out.println(Student.getStudent()); //通过静态方法访问静态成员变量

//        Student.show();


//        Student student001 = new Student();
//        student001.name = "张三";
//        student001.doMeal();
    }

//    public void setStudent(Student this,String name,String gender){
//        this.name = name;
//        this.gender = gender;
//    }
//    public void doClass(Student this){
//        System.out.println(this.name + "去上课");
//    }
//    public void doHomework(Student this){
//        System.out.println(this.name + "去干作业");
//    }
//    public void doMeal(Student this){
//        System.out.println(this.name + "去干饭");
//    }
}
